<template>
  <div class="dashboard-container">
    <div class="dashboard-text">name: {{ name }}</div>
    <button @click="test">....</button>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getProfile } from '@/api/user'
export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  methods: {
    async test() {
      try {
        await getProfile()
      } catch (err) {
        if (err.response.data.code === 10002) {
          alert('过期')
          // 1. 删除本地的登录信息
          this.$store.dispatch('user/userLogout')
          // 2. 跳转
          this.$router.push('/login')
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
